﻿/*
 * DisplayTransformMatrix
 * 
 * initial implementation : 20.10.2008
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Drawing;
using Petra.Gis.Geometry.Support;
using Petra.Gis.RenderingServices.PlanarBase;

namespace Petra.Gis.RenderingServices.GDIPlus
{
  /// <summary>
  /// <c>GDIPlus.Map</c>Map render transformation matrix.
  /// Projected (world) coordinate is transformed by given parameters (offset, scale, rotation)
  /// to display on map in small local coordinate system in pixels
  /// this class supports transformation of <c>CoordStruct</c> and can return <c>System.Drawing.Point</c>
  /// </summary>
  public class DisplayTransformMatrix : RenderTransformMatrix
  {
    //private System.Drawing.Drawing2D.DisplayTransformMatrix _matrix ;

    //protected double[] _matrixArray;


    #region construcors

    public DisplayTransformMatrix()
      :base(){}




    public DisplayTransformMatrix(float m11, float m12, float m21, float m22, float dx, float dy)
      : base(m11, m12, m21, m22, dx, dy) { }



    #endregion construcors


    #region public members


    //protected override object projectionToMap(Coordinate inputPoint)
    //{
    //  return this.ProjectionToMap(inputPoint);
    //}


    public Point ProjectionToMap(Coordinate inputPoint)
    {
      Point outPt = new Point();

      ////flip
      //double tmp = inputPoint.X;
      //inputPoint.X = inputPoint.Y;
      //inputPoint.Y = tmp;

      //translate
      inputPoint.X -= _matrixArray[6];
      inputPoint.Y -= _matrixArray[7];

      //scale
      inputPoint.X *= _matrixArray[0];
      inputPoint.Y *= _matrixArray[4];

      outPt.X = (int)inputPoint.X;
      outPt.Y = (int)inputPoint.Y;

      return outPt;
    
    }






    //public override object ProjectionToMap(double X, double Y)
    //{
    //  return this.projectionToMap(X, Y);
    //}


    public Point ProjectionToMap(double X, double Y)
    {
      Point outPt = new Point();

      ////flip
      //double tmp = X;
      //X = Y;
      //Y = tmp;

      //translate
      X -= _matrixArray[6];
      Y -= _matrixArray[7];

      //scale
      X *= _matrixArray[0];
      Y *= _matrixArray[4];

      outPt.X = (int)X;
      outPt.Y = (int)Y;

      return outPt;
    }





    //protected override Coordinate mapToProjection(object inputPoint)
    //{
    //  return MapToProjection((Point)inputPoint);
    //}


    public Coordinate MapToProjection(Point inputPoint)
    {
      Coordinate outPt = new Coordinate(0,0,0);

      //scale
      outPt.X = inputPoint.X / _matrixArray[0];
      outPt.Y = inputPoint.Y / _matrixArray[4];

      //translate
      outPt.X += _matrixArray[6];
      outPt.Y += _matrixArray[7];

      return outPt;
    }


    #endregion public members


  }
}
